// selectionPlugin.js
class SelectionPlugin {
      constructor(container, options = {}) {
        this.container = container;
        this.options = options;
        this.isDragging = false;
        this.selectionStartIndex = null;
        this.selectedClass = options.selectedClass || 'selected';
      }
    
      init() {
        this.container.addEventListener('mousedown', this.handleMouseDown.bind(this));
        this.container.addEventListener('mousemove', this.handleMouseMove.bind(this));
        this.container.addEventListener('mouseup', this.handleMouseUp.bind(this));
        this.container.addEventListener('mouseleave', this.handleMouseUp.bind(this));
    
        // 初始化所有项为未选中状态
        this.clearSelection();
      }
    
      handleMouseDown(event) {
          event.preventDefault(); // 阻止默认行为
          this.isDragging = true;
          this.selectionStartIndex = Array.from(this.container.children).indexOf(event.target);
          this.selectRange(this.selectionStartIndex, this.selectionStartIndex);
      }
    
      handleMouseMove(event) {
            event.preventDefault(); // 阻止默认行为
            const currentIndex = Array.from(this.container.children).indexOf(event.target);
            this.selectRange(this.selectionStartIndex, currentIndex);
      }
    
      handleMouseUp() {
        this.isDragging = false;
      }
    
      selectRange(startIndex, endIndex) {
        const start = Math.min(startIndex, endIndex);
        const end = Math.max(startIndex, endIndex);
    
        this.container.querySelectorAll('.listItem').forEach((item, index) => {
          item.classList.toggle(this.selectedClass, index >= start && index <= end);
        });
      }
    
      clearSelection() {
        this.container.querySelectorAll('.listItem').forEach(item => {
          item.classList.remove(this.selectedClass);
        });
      }
    }
    
    // 导出插件
    if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
      module.exports = SelectionPlugin;
    } else {
      window.SelectionPlugin = SelectionPlugin;
    }